/**
 * @title: SystemRuleMysqlConverter
 * @projectName mscloud
 * @Description TODO
 * @Author
 * @Date 2022/2/22 20:47
 */
package com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.impl;

import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelSystemRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.PullConverter;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
@Component
@Data
public class SystemRuleMysqlConverter implements PullConverter<List<SentinelSystemRuleDTO>, List<SystemRule>>, Converter<List<SentinelSystemRuleDTO>, List<SystemRule>> {
    private long recommendRefreshMs=10000;
    @Override
    public List<SystemRule> convert(List<SentinelSystemRuleDTO> sources) {
        return sources.stream().map(source->{
            SystemRule systemRule=new SystemRule();
            /*JSONObject jsonObject = JSON.parseObject(source);
            systemRule.setLimitApp(jsonObject.getString("limitApp"));
            systemRule.setResource(jsonObject.getString("resource"));
            systemRule.setAvgRt(jsonObject.getLong("avgRt"));
            systemRule.setHighestCpuUsage(jsonObject.getDouble("highestCpuUsage"));
            systemRule.setMaxThread(jsonObject.getLong("maxThread"));
            systemRule.setHighestSystemLoad(jsonObject.getDouble("highestSystemLoad"));
            systemRule.setQps(jsonObject.getDouble("qps"));*/
            systemRule.setLimitApp(source.getLimitApp());
            systemRule.setResource(source.getResource());
            systemRule.setAvgRt(source.getAvgRt());
            systemRule.setHighestCpuUsage(source.getHighestCpuUsage());
            systemRule.setMaxThread(source.getMaxThread());
            systemRule.setHighestSystemLoad(source.getHighestSystemLoad());
            systemRule.setQps(source.getQps());
            return systemRule;
        }).collect(Collectors.toList());
    }
}
